# import os
# while True:
#     file_name = input("请输入文件名：")
#     if os.path.exists(file_name):
#         print("文件已存在！")
#         break
#     else:
#         print("您输入的文件名未查询到，请重试！"
# )
# idx = file_name.rfind(".")
# file_name_L = file_name[:idx]
# file_name_R = file_name[idx:]
# file_new_name = f"{file_name_L}复制{file_name_R}"
# with open(file_name,"rb",encoding="utf-8") as file:
#     content = file.read()
#     print(content,type(content))
#     with open(file_new_name,"wb",encoding="utf-8") as new_file:
#         new_file.write(content)
#         print("拷贝完成！")

import os
while True:
    file_name = input("请输入文件名：")
    if os.path.exists(file_name):
        print("文件已存在！")
        break
    else:
        print("您输入的文件名未查询到，请重试！"
)
idx = file_name.rfind(".")
file_name_L = file_name[:idx]
file_name_R = file_name[idx:]
file_new_name = f"{file_name_L}复制{file_name_R}"
with open(file_name,"rb") as file:#不需要译码encoding
    content = file.read()
    # print(content,type(content))
    with open(file_new_name,"wb") as new_file:
        new_file.write(content)
        print("拷贝完成！")

    
    
    

